class UserIcon < ActiveRecord::Base

	belongs_to	:user
	
	has_attached_file :tmp_pic, 
  									:styles => { :small => "50x50#", :medium => "115x115#", :large => "160x238>" }, 
  									:processors => [:cropper],
  									:url => "/system/pics/:id/:style/:basename.:extension",
  									:path => ":rails_root/public/system/pics/:id/:style/:basename.:extension"

  attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
  after_update :reprocess_pic, :if => :cropping?
  
  def cropping?
    !crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
  end
  
  def pic_geometry(style = :original)
    @geometry ||= {}
    @geometry[style] ||= Paperclip::Geometry.from_file(tmp_pic.path(style))
  end
  
  private

	def reprocess_pic
  	pic.reprocess!
  	
  	#copy pic
  	#保存坐标
	end
end
